<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@page import="com.vince.model.domain.*,java.lang.*" %>
    <%@taglib prefix='c' uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
	function change(value){
		 if(value=="1"){
			 form1.discount.disabled="disabled";
			 form1.promotionprice.disabled="disabled";
			 form1.promotionnum.disabled="disabled";
			 
		 }else if(value=="2"){
			 form1.discount.disabled="";
			 form1.promotionprice.disabled="disabled";
			 form1.promotionnum.disabled="disabled";
		 }else if(value=="3"){
			 form1.discount.disabled="disabled";
			 form1.promotionprice.disabled="";
			 form1.promotionnum.disabled="";
		 }
	 }
	function getSum(){
		
		if(document.getElementById("zero").value=="1"){
			if(document.getElementById("zero1")!=null&&document.getElementById("zero2")!=null){
				
				document.getElementById("sum").value=document.getElementById("zero1").value*document.getElementById("zero2").value;
				
			}
			
		}else if(document.getElementById("zero").value=="2"){
	
			if(document.getElementById("zero1")!=null&&document.getElementById("zero2")!=null&&document.getElementById("one")!=null){
				document.getElementById("sum").value=document.getElementById("zero1").value*document.getElementById("zero2").value
				*document.getElementById("one").value;
			}
			
		}else if(document.getElementById("zero").value=="3"){
	
			if(document.getElementById("zero1")!=null&&document.getElementById("zero2")!=null&&document.getElementById("two")!=null&&document.getElementById("three")!=null){
				document.getElementById("sum").value=(document.getElementById("zero1").value-document.getElementById("three").value)*document.getElementById("zero2").value+
				document.getElementById("three").value*document.getElementById("two").value;

			}
			
		}
		
	}
	window.onload=function(){
		
		 if(form1.discounttype.value=="1"){
			 form1.discount.disabled="disabled";
			 form1.promotionprice.disabled="disabled";
			 form1.promotionnum.disabled="disabled";
			 
		 }else if(form1.discounttype.value=="2"){
			 form1.discount.disabled="";
			 form1.promotionprice.disabled="disabled";
			 form1.promotionnum.disabled="disabled";
		 }else if(form1.discounttype.value=="3"){
			 form1.discount.disabled="disabled";
			 form1.promotionprice.disabled="";
			 form1.promotionnum.disabled="";
		 }
		
	}
</script>
</head>
<body>

<h2>查看/修改订单明细</h2>
<form action="<%=request.getContextPath()%>/servlet/itemsservlet?method=update&itemid=${requestScope.itemobj.itemid}" method="post" name='form1'>
 <table border='1'>
 <tr>
  <td colspan='2'>订单id<input name="orderid" type="text" value=${requestScope.itemobj.orderId}></td>
 </tr>
 <tr>
  <td>货物名称<input type="text" name="itemname" value=${requestScope.itemobj.name}></td>
  <td>折扣类型
  <c:choose>
   <c:when test="${requestScope.itemobj.discountType eq 1}">
	   <select name="discounttype" onchange="change(this.value)" id="zero">
	    <option value="1" selected="selected">normal</option>
	    <option value="2">discount</option>
	    <option value="3">promotion</option>
	   </select>
   
   </c:when>
   <c:when test="${requestScope.itemobj.discountType eq 2}">
	   <select name="discounttype" onchange="change(this.value)" id="zero">
	    <option value="1" >normal</option>
	    <option value="2" selected="selected">discount</option>
	    <option value="3">promotion</option>
	   </select>
   </c:when>
   <c:otherwise>
	  <select name="discounttype" onchange="change(this.value)" id="zero">
	   <option value="1" >normal</option>
	   <option value="2">discount</option>
	   <option value="3" selected="selected">promotion</option>
	  </select>
   </c:otherwise>
  </c:choose>
  </td>
 </tr>
 <tr>
   <td>货物数量<input type='text' name='unitnum' id="zero1" value=${requestScope.itemobj.unitNum}></td>
   <td>货物单价<input type="text" name="unitprice" id="zero2" value=${requestScope.itemobj.unitPrice}></td>
 </tr>
 <tr>
  <td>货物总价<input type="text" name="sum" onfocus="getSum()" id="sum" value=${requestScope.itemobj.sum}></td>
  <td>折扣率
  <c:choose>
   <c:when test='<%=request.getAttribute("itemobj").toString().contains("Discount")%>'>
           <input type="text" name="discount" id="one" value=${requestScope.itemobj.discount}>
   </c:when>
   <c:otherwise>
           <input type="text" name="discount" disabled="disabled" id="one"}>
   </c:otherwise>
  </c:choose>

 
  </td>
 </tr>
 <tr>
   <c:choose>
    <c:when test='<%=request.getAttribute("itemobj").toString().contains("Promotion")%>'>
   <td>促销单价
      <input type="text" name="promotionprice"  id="two"  value=${requestScope.itemobj.promotionPrice}>
   </td>
   <td>促销数量
      <input type="text" name="promotionnum"  id="three"  value=${requestScope.itemobj.promotionNum}>
   </td>
    </c:when>
    <c:otherwise>
    <td>促销单价
      <input type="text" name="promotionprice"  id="two"  disabled="disabled" }>
   </td>
   <td>促销数量
      <input type="text" name="promotionnum"  id="three"  disabled="disabled"}>
   </td>
    </c:otherwise>
   </c:choose>
 </tr>
</table>
 <input type="submit" value="保存">
</form>
<br/>
 <input type="submit" onclick="document.location.href='<%=request.getContextPath() %>/servlet/itemsservlet?method=list&orderid='+${requestScope.itemobj.orderId}" value="返回">

</body>
</html></html>